clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

******************************************************************************************
********************************** Table S10: Robustness test – Alternative samples
******************************************************************************************

use "${date}/_data/spid_for_analysis_v2.dta", clear

encode geo_code2_new, gen(id_region)
bysort id_region: gen N=_N
gen ADM = (strpos(geo_code2_new, "ADM1") > 0) | (strpos(geo_code2_new, "GADM1") > 0)

preserve
collapse (mean) temp, by(code)
xtile temp_pct = temp, n(100)  
tempfile country_temp
save `country_temp'
restore

sort code
	merge m:1 code using `country_temp'
	drop _merge
	
sort geo_code2_new year
	merge m:1 geo_code2_new year using "${date}/_data/weight.dta"
	drop _merge

sort geo_code2_new
	merge m:1 geo_code2_new using "${date}/_data/coordinate.dta", force
	drop _merge
	
local controls ln_GDPppp Unempilo agri manuf popgr 
	
// Headcount Poverty
estimates clear
qui reghdfe poor215 temp rainfall_sum humid `controls' if N!=1, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
qui reghdfe poor215 temp rainfall_sum humid `controls' if ADM==1, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2
qui reghdfe poor215 temp rainfall_sum humid `controls' if code!="USA", absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
qui reghdfe poor215 temp rainfall_sum humid `controls' if code!="IND", absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4	
qui reghdfe poor215 temp rainfall_sum humid `controls' if temp_pct>=5, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m5
qui reghdfe poor215 temp rainfall_sum humid `controls' if temp_pct<=95, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m6
qui reghdfe poor215 temp rainfall_sum humid `controls' [pw= noind], absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle
	est store m7
drop if latitude==.
qui acreg poor215 temp rainfall_sum humid `controls' if id_region!=., latitude(latitude) longitude(longitude) dist(50) spatial pfe1(id_region) pfe2(year) 
	est store m8
qui reghdfe poor215 temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(code) keepsingle	
	est store m9
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) ///
	collabels(,none) keep(temp)	
	
esttab m*, `opts'	
esttab m* using "${date}/_tables/_tab_s10a.csv", replace `opts'

	
// Inequality	
estimates clear
qui reghdfe gini temp rainfall_sum humid `controls' if N!=1, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
qui reghdfe gini temp rainfall_sum humid `controls' if ADM==1, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2
qui reghdfe gini temp rainfall_sum humid `controls' if code!="USA", absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
qui reghdfe gini temp rainfall_sum humid `controls' if code!="IND", absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4
qui reghdfe gini temp rainfall_sum humid `controls' if temp_pct>=5, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m5
qui reghdfe gini temp rainfall_sum humid `controls' if temp_pct<=95, absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m6
qui reghdfe gini temp rainfall_sum humid `controls' [pw= noind], absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle
	est store m7
drop if latitude==.
qui acreg gini temp rainfall_sum humid `controls' if id_region!=., latitude(latitude) longitude(longitude) dist(50) spatial pfe1(id_region) pfe2(year) 
	est store m8
qui reghdfe gini temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(code) keepsingle	
	est store m9
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) ///
	collabels(,none) keep(temp)	
	
esttab m*, `opts'	
esttab m* using "${date}/_tables/_tab_s10b.csv", replace `opts'
